<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增维保项目合同')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-contact-add" name="payment_form" action="payment.php" method="post">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">合同名称：</label>
            <div class="col-sm-8">
                <input id="mtContractName" name="mtContractName" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">上传维保合同：</label>
            <div class="col-sm-8">
                <input id="mtContractUpload" name="file" class="form-control" type="file">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">维保费用金额：</label>
            <div class="col-sm-8">
                <input id="mtPrice" name="mtPrice" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">付款方式：</label>
            <div class="col-sm-8">
                <input id="mtPayMethod" name="mtPayMethod" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">维保合同起始日期：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input id="mtContractDate" name="mtContractDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">开具维保费发票：</label>
            <ul style="list-style-type:none; margin-top: 5px">
                <li style="display:inline; margin-right: 10px; margin-left: 15px">
                    <input type="radio" name="mtInvoiceStatus" value="1" id="mtInvoiceStatus1" checked onclick="otherpays()">
                    <label th:for="mtInvoiceStatus" th:text="是"></label>
                </li>
                <li style="display:inline;">
                    <input type="radio" name="mtInvoiceStatus" value="0" id="mtInvoiceStatus2" onclick="predeposit()">
                    <label th:for="mtInvoiceStatus" th:text="否"></label>
                </li>
            </ul>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">甲方签收维保费发票：</label>
            <ul style="list-style-type:none; margin-top: 5px;">
                <li style="display:inline; margin-right: 10px; margin-left: 15px">
                    <input type="radio" id="otherpayment1" name="mtInvoiceSignfor" value="1" onclick="showmtInvoiceUL()" checked>
                    <label th:for="mtInvoiceStatus" th:text="是"></label>
                </li>
                <li style="display:inline">
                    <input type="radio" id="otherpayment2" name="mtInvoiceSignfor" value="0" onclick="mtInvoiceUL()">
                    <label th:for="mtInvoiceStatus" th:text="否"></label>
                </li>
                <li style="display:inline; display: none">
                    <input type="radio" id="otherpayment3" name="mtInvoiceSignfor" value="0">
                    <label th:for="mtInvoiceStatus" th:text="否"></label>
                </li>
            </ul>
        </div>
        <div id="mtInvoiceUL" class="form-group">
            <label class="col-sm-3 control-label">上传签收维保费发票证明：</label>
            <div class="col-sm-8">
                <input id="mtInvoiceUpload" name="file1" class="form-control" type="file">
            </div>
        </div>
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label is-required">维保费发票是/否开具：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <div class="radio-box">-->
<!--                    <input type="radio" name="mtInvoiceStatus" value="1" checked>-->
<!--                    <label th:for="mtInvoiceStatus" th:text="是"></label>-->
<!--                </div>-->
<!--                <div class="radio-box">-->
<!--                    <input type="radio" name="mtInvoiceStatus" value="0">-->
<!--                    <label th:for="mtInvoiceStatus" th:text="否"></label>-->
<!--                </div>-->
<!--                &lt;!&ndash;                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>&ndash;&gt;-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label is-required">维保费发票是/否送至甲方并签收：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <div class="radio-box">-->
<!--                    <input type="radio" name="mtInvoiceSignfor" value="1" checked>-->
<!--                    <label th:for="mtInvoiceStatus" th:text="是"></label>-->
<!--                </div>-->
<!--                <div class="radio-box">-->
<!--                    <input type="radio" name="mtInvoiceSignfor" value="0">-->
<!--                    <label th:for="mtInvoiceStatus" th:text="否"></label>-->
<!--                </div>-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="form-group">-->
<!--            <label class="col-sm-3 control-label">维保费发票上传：</label>-->
<!--            <div class="col-sm-8">-->
<!--                <input id="mtInvoiceUpload" name="file1" class="form-control" type="file">-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group" hidden>
            <label class="col-sm-3 control-label">伪外键：</label>
            <div class="col-sm-8">
                <input id="mtId" name="mtId" class="form-control" type="text" th:value="${mtId}">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script type="text/javascript">
    var prefix = ctx + "ruoyi/contact"
    $("#form-contact-add").validate({
        focusCleanup: true
    });
    function submitHandler() {
        if ($.validate.form()) {
            uploadFile();
        }
    }
    function uploadFile() {
        var formData = new FormData();
        if ($('#mtContractUpload')[0].files[0] == null&&$('#mtInvoiceUpload')[0].files[0] == null) {
            $.modal.alertWarning("请先选择文件路径");
            return false;
        }
        if ($('#mtContractUpload')[0].files[0] != null&&$('#mtInvoiceUpload')[0].files[0] != null) {
            formData.append('mtContractName', $("#mtContractName").val());
            formData.append('mtPrice', $("#mtPrice").val());
            formData.append('mtPayMethod', $("#mtPayMethod").val());
            formData.append('mtContractDate', $("#mtContractDate").val());
            formData.append('mtInvoiceStatus', $("input[name='mtInvoiceStatus']:checked").val());
            formData.append('mtInvoiceSignfor', $("input[name='mtInvoiceSignfor']:checked").val());
            formData.append('file', $('#mtContractUpload')[0].files[0]);
            formData.append('file1', $('#mtInvoiceUpload')[0].files[0]);
            formData.append('mtId',$("#mtId").val());
            $.ajax({
                url: prefix + "/add",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }else if($('#mtContractUpload')[0].files[0] != null&&$('#mtInvoiceUpload')[0].files[0] == null){
            formData.append('mtContractName', $("#mtContractName").val());
            formData.append('mtPrice', $("#mtPrice").val());
            formData.append('mtPayMethod', $("#mtPayMethod").val());
            formData.append('mtContractDate', $("#mtContractDate").val());
            formData.append('mtInvoiceStatus', $("input[name='mtInvoiceStatus']:checked").val());
            formData.append('mtInvoiceSignfor', $("input[name='mtInvoiceSignfor']:checked").val());
            formData.append('file', $('#mtContractUpload')[0].files[0]);
            formData.append('mtId',$("#mtId").val());
            $.ajax({
                url: prefix + "/addone",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });

        }
    }

    // function submitHandler() {
    //     if ($.validate.form()) {
    //         $.operate.save(prefix + "/add", $('#form-contact-add').serialize());
    //     }
    // }

    $("input[name='mtContractDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
    // 点击未开发票
    function predeposit(){
        document.payment_form.otherpayment1.disabled=true;
        document.payment_form.otherpayment1.checked=false;
        document.payment_form.otherpayment2.disabled=true;
        document.payment_form.otherpayment2.checked=false;
        document.payment_form.otherpayment3.checked=true;
        document.getElementById('mtInvoiceUL').style.display="none";
    }
    // 点击已开发票
    function otherpays(){
        document.payment_form.otherpayment2.disabled=false;
        document.payment_form.otherpayment2.checked=false;
        document.payment_form.otherpayment1.disabled=false;
        document.payment_form.otherpayment1.checked=true;
        document.getElementById('mtInvoiceUL').style.display="";
    }
    function mtInvoiceUL() {
        document.getElementById('mtInvoiceUL').style.display="none";
    }
    function showmtInvoiceUL() {
        document.getElementById('mtInvoiceUL').style.display="";
    }
</script>
</body>
</html>